import requests
import json 
from fastapi import FastAPI

from fastapi.middleware.cors import CORSMiddleware

origins = [
    "*"
]

app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/login/test")
async def login_test():
    return {
    "data": {
        "code": 200,
        "account": {
            "id": 502853833,
            "userName": "1_********671",
            "type": 1,
            "status": 0,
            "whitelistAuthority": 0,
            "createTime": 1512640135326,
            "tokenVersion": 0,
            "ban": 0,
            "baoyueVersion": -2,
            "donateVersion": 0,
            "vipType": 11,
            "anonimousUser": "false",
            "paidFee": "true"
        },
        "profile": {
            "userId": 502853833,
            "userType": 0,
            "nickname": "jan17th",
            "avatarImgId": 109951168497529150,
            "avatarUrl": "http://p2.music.126.net/MCr9n4oCcXH1abjWTAXX3w==/109951168497529144.jpg",
            "backgroundImgId": 109951162868128400,
            "backgroundUrl": "http://p1.music.126.net/2zSNIqTcpHL2jIvU6hG0EA==/109951162868128395.jpg",
            "signature": "null",
            "createTime": 1512640146738,
            "userName": "1_********671",
            "accountType": 1,
            "shortUserName": "********671",
            "birthday": -2209017600000,
            "authority": 0,
            "gender": 1,
            "accountStatus": 0,
            "province": 330000,
            "city": 330300,
            "authStatus": 0,
            "description": "null",
            "detailDescription": "null",
            "defaultAvatar": "false",
            "expertTags": "null",
            "experts": "null",
            "djStatus": 0,
            "locationStatus": 10,
            "vipType": 11,
            "followed": "false",
            "mutual": "false",
            "authenticated": "false",
            "lastLoginTime": 1708351602248,
            "lastLoginIP": "127.0.0.1",
            "remarkName": "null",
            "viptypeVersion": 1700446451361,
            "authenticationTypes": 0,
            "avatarDetail": "null",
            "anchor": "false"
        }
    }
}
# resp = requests.get('http://localhost:4000/login/qr/key')
# key = json.loads(resp.text)['data']['unikey']
# print(key)
# qr = requests.get(f'http://localhost:4000/login/qr/create?key={key}')

# print(qr.text)

#  to cookies
# csrftoken	nZueS3It5oB9XSLw4775Xf49yWCpMjkF	localhost	/	2025/1/1 20:03:24	41 B			Lax
# csrftoken=nZueS3It5oB9XSLw4775Xf49yWCpMjkF; Path=/; Expires=Mon, 19 Feb 2024 14:47:32 GMT;

# def cookie_to_dict(cookie):
#     cookie_dict = {}
#     for c in cookie.split(';'):
#         if len(c.split('=')) == 1:
#             continue
#         k, v = c.split('=')
#         cookie_dict[k.strip()] = v
#     return cookie_dict

# csrftoken = 'csrftoken=nZueS3It5oB9XSLw4775Xf49yWCpMjkF; Path=/; Expires=Mon, 19 Feb 2024 14:47:32 GMT;'
# csrftoken_dict = cookie_to_dict(csrftoken)
# cookies = 'MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/neapi/feedback; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/weapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/wapi/clientlog; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/neapi/clientlog; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/weapi/feedback; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/wapi/clientlog; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/openapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/eapi/feedback; HTTPOnly;MUSIC_SNS=; Max-Age=0; Expires=Mon, 19 Feb 2024 14:06:42 GMT; Path=/;__csrf=99715ab2d4bea72659b5cdd229955d37; Max-Age=1296010; Expires=Tue, 05 Mar 2024 14:06:52 GMT; Path=/;;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/wapi/feedback; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/api/clientlog; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/api/feedback; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/eapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/openapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/weapi/feedback; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/wapi/feedback; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/api/feedback; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/neapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/eapi/clientlog; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/api/clientlog; HTTPOnly;MUSIC_U=000CBC062216E217183D556B565D14624491D8FADC1414F52F8508BCBA42EF8FBF92F0ADD950409C930B9030B2936A169024A9446CF31C29F07C059CE94B22BF2A30A3D2845EEC0EB10183C9CEC41B12611D07BFB9DA5D101B3ACAE35381F5BF487AC5B3E51A78E838E93A165633ED5A734C0993A8910ACCAD0409B49F0E4234CF6B90484043A8D9145F229505DBCB98D829370EAB90679CFE28BB5FF47091A290544E0B2D0FC75856855AEB22C657C06947FB358C7BC916236ECCBA2BDE1492BE6C1BD453821E257E48537E50B73ED87FD468186146E2D38E6210170D4357E4B194FB0C09595D77FCF3158FB8253AB7A358F598521D3F7684288B01B1CDA3DEDBDC24A2D6842BC4F0E0AAAB5EB370FABC09CCA1CBB52153D19590101C2A2F61ED733150F76468579A59AEA8000AF801179B52E0C576C3B85C8FF5EEBFAD476697; Max-Age=15552000; Expires=Sat, 17 Aug 2024 14:06:42 GMT; Path=/; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/eapi/feedback; HTTPOnly;MUSIC_A_T=1512640135326; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/neapi/feedback; HTTPOnly;MUSIC_R_T=1512640146738; Max-Age=2147483647; Expires=Sat, 08 Mar 2092 17:20:49 GMT; Path=/weapi/clientlog; HTTPOnly'
# cookies_dict = cookie_to_dict(cookies)
# res = requests.get('http://localhost:4000/song/url/v1?id=5052317&level=lossless', cookies=cookies_dict, headers={'X-CSRF-Token': csrftoken_dict['csrftoken']})
# print(res.text)


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0",port=5678)
